package com.boruan.qq.zxgylibrary.utils;

import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;

/**
 * Created by 崔琦 on 2019/8/19.
 * des: ....
 */

public class CallPhoneUtils {
    /**
     * 申请权限 拨打电话
     * @param mobile
     */
    public static void requestPermission(String mobile, Activity context){
        //判断Android版本是否大于23
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
            int checkCallPhonePermission = ContextCompat.checkSelfPermission(context, Manifest.permission.CALL_PHONE);
            if (checkCallPhonePermission != PackageManager.PERMISSION_GRANTED) {
                ActivityCompat.requestPermissions(context, new String[]{Manifest.permission.CALL_PHONE},
                        RequestPermissionType.REQUEST_CODE_ASK_CALL_PHONE);
                return;
            }
            else {
                context.startActivity(new Intent(Intent.ACTION_CALL).setData(Uri.parse("tel:"+ mobile)));
            }
        }
        else {
            context.startActivity(new Intent(Intent.ACTION_CALL).setData(Uri.parse("tel:"+ mobile)));
        }
    }
}
